local ArticleController = {}
local db = require 'models.db'
local cache = require ('library.cache'):new()
local helper = require 'library.helpers'

function ArticleController:_init_cache(action_name,controller_name)
    local get = self:getRequest():getParams()
    if action_name=='index' then
        local id=helper:intval(get['id'])
        local response= self:getResponse()
        response.cache_name="article/index/id-"..id
        response.cache_life=helper:intval(helper:config_get('article_cache')) 
    end
end

function ArticleController:index()
    local p = {}
    local get = self:getRequest():getParams()

    local id=helper:intval(get['id'])
   	local cache_name="article/index-"..id

    local article_db=db:new('article')    

    p['article'] = article_db:where("id=?",id):get_one()
    p['page'] = helper:intval(get['page']) 
    if not p['article'] then
    	response.cache_name="article/index/id-0"
    end

    return self:display(p)
end

return ArticleController
